package edu.lfsy.rabbitmqdemo.config;

import org.springframework.amqp.core.*;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.amqp.support.converter.MessageConverter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author 王希辰
 * @date 2022/4/16 23:36
 */
@Configuration
public class RabbitMQConfig {
    //自定义消息转换器
    @Bean
    public MessageConverter messageConverter(){
        return new Jackson2JsonMessageConverter();
    }
    /*//采用Publish/Subscribe模式
    //1.定义fanout类型交换器
    @Bean
    public Exchange fanout_exchange(){
        return ExchangeBuilder.fanoutExchange("fanout_exchange").build();
    }
    //2.定义两个不同名称的消息队列，分别处理email与sms消息
    @Bean
    public Queue fanout_exchange_email(){
        return new Queue("fanout_exchange_email");
    }


    @Bean
    public Queue fanout_exchange_sms(){
        return new Queue("fanout_exchange_sms");
    }
    //3.将两个不同名称的消息队列与交换机进行绑定
    @Bean
    public Binding bindingEmail(){
        return BindingBuilder.bind(fanout_exchange_email()).to(fanout_exchange())
                .with("").noargs();
    }
    @Bean
    public Binding bindingSms(){
        return BindingBuilder.bind(fanout_exchange_sms()).to(fanout_exchange())
                .with("").noargs();
    }*/
    @Bean
    public Exchange fanoutExchange() {
        return new FanoutExchange("fanoutExchange");
    }
    @Bean
    public Queue fanout_exchange_email(){
        return new Queue("fanout_exchange_email");
    }
    @Bean
    public Binding bindingEmail(){
        return BindingBuilder.bind(fanout_exchange_email()).to(fanoutExchange())
                .with("").noargs();
    }



































}
